<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<#include '/common/head.html'>
	<script type="text/javascript">
		var $obj = {}, $tg , $window ;
		$(function() {
			$obj = {
				init: function() {
					$tg = $('#tg').treegrid({
						title: '菜单管理',
						url: '/menu/list', 
						method: 'GET', idField: 'id', treeField: 'name',
						fit: true, border: false, rownumbers: true, rownumberWidth: 40, toolbar: "#toolbars",
						frozenColumns: [[
							{title: 'ID', field: 'id', hidden: true},
							{title: '排序', field: 'orderNum', width: 50},
							{title: '菜单名称', field: 'name', width: 200}
						]],
						columns: [[
							{title: '状态', field: 'status', width: 70, align: 'center', formatter: function(value, row, index) {
								if(value==0) return '禁用';
								else if(value==1) return '正常';
								else return '-';
							}},
							{title: '菜单代码', field: 'code', width: 150},
							{title: '权限代码', field: 'permission', width: 150},
							{title: 'URL', field: 'url', width: 400},
							{title: '菜单类型', field: 'type', width: 80, align: 'center', formatter: function(value, row, index) {
								if(value==1) return '<span style="color:red">顶级菜单</span>';
								else if(value==2) return '<span style="color:orange">菜单目录</span>';
								else if(value==3) return '<span style="color:green">导航菜单</span>';
								else if(value==4) return '<span style="color:gray">功能按钮</span>';
								else return '-';
							}},
							{title: '叶子', field: 'leaf', width: 50, align: 'center', formatter: function(value, row, index) {
								if(value==0) return '否';
								else if(value==1) return '是';
								else return '-';
							}},
							{title: '选中', field: 'choose', width: 50, align: 'center', formatter: function(value, row, index) {
								if(row.type == 1) {
									if(value == 0) return '否';
									else if(value == 1) return '<span style="color:red">是</span>';
								} else {
									return '-';
								}
							}},
							{title: '图标', field: 'icon', width: 60, align: 'center', formatter: function(value, row, index) {
								if(undefined != value) return '<i class="'+value+'" style="color:#0A819C"></i>';
								else return '-';
							}},
							{title: '打开方式', field: 'iniframe', width: 80, align: 'center', formatter: function(value, row, index) {
								if(value==0) return 'panel';
								else if(value==1) return 'frame';
								else return '-';
							}},
							{title: '备注信息', field: 'remarks', width: 300},
							{title: '创建时间', field: 'createTime', width: 130, align: 'center', formatter: function(value, row, index) {
								return value != null && value != '' ? $.date.format(value, 'yyyy-MM-dd HH:mm:ss') : '';
							}},
							{title: '创建者', field: 'createBy', width: 70},
							{title: '更新时间', field: 'updateTime', width: 130, align: 'center', formatter: function(value, row, index) {
								return value != null && value != '' ? $.date.format(value, 'yyyy-MM-dd HH:mm:ss') : '';
							}},
							{title: '更新者', field: 'updateBy', width: 70}
						]]
					});
				},
				add: function() {
					var row = $tg.treegrid('getSelected') ;
					$window = MM.addWindow({title: '添加', href: '/menu/form?pid='+(null!=row?row.id:''), width: 600, height: 391});
				},
				del: function() {
					var ids = MM.getSelectionsIds('#tg') ;
					if(ids) {
						$.messager.confirm('删除确认', '确定要删除？', function(r) {
							if(r) {
								$.get('/menu/delete/'+ids, function(result) {
									try {
										if(result.code == 200) {
											$obj.reload(); alertify.success(result.message);
										} else {
											alertify.warning(result.message);
										}
									} catch(e) {
										$.easyui.loaded(); console.error(e) ;
									}
								}, 'JSON').complete(function(){$.easyui.loaded();});
							}
						});
					} else {
						alertify.error('至少选择一条记录');
					}
				},
				update: function() {
					var row = $tg.treegrid('getSelected') ;
					if(null != row && row.id != "") {
						$window = MM.addWindow({title: '修改', href: '/menu/form?id='+row.id, width: 600, height: 391});
					} else {
						alertify.error('请选择一条记录');
					}
				},
				reload: function() {
					$tg.treegrid('reload'); $tg.treegrid('clearSelections');$tg.treegrid('clearChecked');
				},
				clearCache: function() {
					$.get('/menu/clearCache', function(result) {
						try {
							if(result.code == 200) {
								$obj.reload(); alertify.success(result.message);
							} else {
								alertify.warning(result.message);
							}
						} catch(e) {
							$.easyui.loaded(); console.error(e) ;
						}
					}, 'JSON').complete(function(){$.easyui.loaded();});
				}
			};
			
			$obj.init() ;
		});
	</script>
</head>

<body>
	<div id="tg">
		<div id="toolbars"> 
			<a onclick="$obj.add();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-add'">添加</a> 
			<a onclick="$obj.update();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-edit'">编辑</a> 
			<a onclick="$obj.del();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-cancel'">删除</a> 
			<a onclick="$obj.reload();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-reload'">刷新</a> 
			<a onclick="$obj.clearCache();" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-reload'">清空缓存</a> 
		</div>
	</div>
</div>

</body>
</html>
